package com.doublefish.doublefishrobot.ui.home.path.bean;

/**
 * 作者:dugaofeng on 2025/4/9 15:36
 *
 * 速度（矢量）的模型
 */
public class VelocityBean {

    private float vx;   //x轴 左负右正
    private float vy;   //y轴 后负前正
    private float vz;   //z轴 下负上正

    //只读属性
    private float speed;  //速度（标量 无方向）
    private float sumOfSquares;  //平方和

    //为了避免重复计算 用几个中间变量做记录
    private boolean _flag;
    private float _sum;
    private float _spd;


    public float getVx() {
        return vx;
    }

    public void setVx(float vx) {
        this.vx = vx;
        this._flag = false;
    }

    public float getVy() {
        return vy;
    }

    public void setVy(float vy) {
        this.vy = vy;
        this._flag = false;
    }

    public float getVz() {
        return vz;
    }

    public void setVz(float vz) {
        this.vz = vz;
        this._flag = false;
    }



    public float getSumOfSquares() {
        if (this._flag) {
            return this._sum;
        }
        this._flag = true;
         this._sum = (this.vx * this.vx + this.vy * this.vy + this.vz * this.vz);
        return this._sum;
    }

    public float getSpeed() {
        if (this._flag) {
            return this._spd;
        }
        this._spd = (float) Math.sqrt(this.getSumOfSquares());
        return this._spd;
    }

}
